<?php
	session_start();
	require_once('site/class/utility.php');
	include("site/pre_header.php");
?>
<body>
<div id="main">
	<?php
        include("site/header.php");
		echo '<div id="allcontents">';
        include("site/sideleft.php");
        include("site/sideright.php");

	if(isset($_GET['content_type']))
	{
		$content_type 	= $_GET['content_type'];
		$category 		= $_GET['category'];
		$cat_id = $_GET['cat_id'];
	}
	$result = utility::getCats();
?>
        
	<div id="content">
    <?php
		if($category == 'all')
		{
			echo '<h3 align="center">All Categories</h3>';
			echo '<ul class="cat-page">';
			foreach($result as $res)
			{
				$count = utility::countByCat($res['id'],$content_type);
				echo '<li><a href="/bizbuddy.com/'.$content_type.'-'.$res['id'].'.'.$res['name'].'.php">'.$res['name'].'&nbsp;&nbsp;&nbsp;('.$count[0]['total'].')</a></li>';
			}
			echo '</ul>';
		}
		else
		{
			$posts = utility::getPostsByCat($cat_id,$content_type);
			echo '<h3 align="center">'.$category.'</h3><br/>';
			if($posts == null)
				echo 'No Posts within this Category!';
			else
			{
				foreach($posts as $post)
				{
					?>
					<div class="highlights">
						<img class="thumbnail" src="<?php echo $post['image'];?>" >
						<h3 id="title"><a href="<?php echo $post['urls'].$post['id'].'-'.str_replace(' ','_',$post['name']).'.php';?>"><?php echo $post['name'];?></a></h3>
						<p class="description"><?php echo substr($post['description'],0,150).'...';?></p>
					</div>
				 <?php
				 }
			}
		}
    ?>
    </div>

<?php
		echo '</div>';
        include("site/footer.php");
    ?>
</div>
<body>
</body>
</html>